package com.rao.quartz.controller;

import com.rao.response.ResultCodeEnum;
import com.rao.quartz.service.impl.TestServiceImpl;
import com.rao.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;

/**
 * @Author: raoguang
 * @Date: 2022/05/28/22:05
 * @Description:
 */
@RestController
public class TestController {

    @Autowired
    private TestServiceImpl testService;

    @RequestMapping("/user/detail")
    public String userDetail() {
        return "/user/detail";
    }

    @RequestMapping("/center")
    public String center() {
        return "/center";
    }

    @GetMapping("/testhealth")
    public String health() {
        return "I'm fine ,and you???";
    }

    @GetMapping("/health/{name}")
    public String test01(@PathVariable("name") String names) {
        System.out.println("进入了测试的health方法了！！！");
        return testService.TestWay(names);
    }

    @RequestMapping("/login/{username}/{pwd}")
    public boolean login(HttpSession session, @PathVariable("username") String name, @PathVariable("pwd") String password) {
        if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(password)) {
            session.setAttribute("names", name);
            session.setAttribute("passwords", password);
        } else {
            return false;
        }
        return true;
    }


    @GetMapping("/successTest")
    public Result<String> successTest() {
        return Result.success();
    }

    @GetMapping("/failTest")
    public Result<String> failTest() {
        return Result.error(ResultCodeEnum.BIZ_ERROR.getCode(), ResultCodeEnum.BIZ_ERROR.getMsg());
    }
}
